﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library
{
    public class UserSystemNoLocalData : BaseUserSystem
    {
        protected override void AddUser(string username, string password, int role)
        {
            var existingUser = Users.Find(user => user.UserName == username);
            if (existingUser != null) Console.WriteLine($"用户: {username} 已存在!");
            else
            {
                Users.Add(new(username, password, role));
                Console.WriteLine($"添加用户: {username} 成功!");
            }
        }

        protected override void ChangePassword(User user, string password)
        {
            user.Password = password;
            Console.WriteLine("密码修改成功!");
        }

        protected override void DeleteUser(string username)
        {
            var existingUser = Users.Find(user => user.UserName == username);
            if (existingUser != null)
            {
                Users.Remove(existingUser);
                Console.WriteLine($"删除用户: {username} 成功!");
            }
            else Console.WriteLine($"用户: {username} 不存在!");
        }

        protected override void ResetPassword(string username)
        {
            var existingUser = Users.Find(user => user.UserName == username);
            if (existingUser != null)
            {
                existingUser.Password = "123456";
                Console.WriteLine("重置密码成功!");
            }
            else Console.WriteLine($"用户: {username}不存在!");
        }
    }
}
